-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve types for ThrottlingOctokitOptions
#457
Conversation
src/index.d.ts
Outdated
}; | ||
} | ||
|
||
export type OctokitThrottlingOptions = OctokitOptions | ThrottlingOptions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A loooong time without touching TS. If I don't do this Union
the compiler does not allow me to use ThrottlingOptions
in a place where OctokitOptions
is expected.
Doing this union we are not making options.throttle
mandatory which is not good.
I still have to play around, maybe with generics OctokitOptions<T>
?
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
ThrottlingOctokitOptions
ThrottlingOctokitOptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
Left some comments
src/index.d.ts
Outdated
}; | ||
} | ||
|
||
export type OctokitThrottlingOptions = OctokitOptions | ThrottlingOptions; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
04e3648
to
c567474
Compare
We can get better types for Bottleneck. They just aren't published to npm for some reason. We'll have to vendor them in the repo. https://github.com/SGrondin/bottleneck/blob/master/light.d.ts As for the options type, I'm not entirely sure. |
I had to create a TS Playground to explain the problem: Basically the Any ideas on how to bypass this? Would this imply to rethink |
If I understand what you're wanting correctly (which is that when Roughly: interface OctokitOptions {
authStrategy?: any;
auth?: any;
userAgent?: string;
previews?: string[];
baseUrl?: string;
log?: {
debug: (message: string) => unknown;
info: (message: string) => unknown;
warn: (message: string) => unknown;
error: (message: string) => unknown;
};
request?: any //OctokitTypes.RequestRequestOptions;
timeZone?: string;
[option: string]: unknown
};
interface OctokitOptions {
throttle?: ThrottlingOptions;
}
interface ThrottlingOptions {
enabled?: boolean;
Bottleneck?: any;
id?: string;
timeout?: number;
connection?: any;
onAbuseLimit: LimitHandler;
onRateLimit: LimitHandler;
} See playground This requires that the type be an Once that change has been made, the final code will be something like this: declare module '@octokit/core' {
interface OctokitOptions {
throttle?: ThrottlingOptions;
}
}
interface ThrottlingOptions {
enabled?: boolean;
Bottleneck?: any;
id?: string;
timeout?: number;
connection?: any;
onAbuseLimit: LimitHandler;
onRateLimit: LimitHandler;
} (module pathing can be a bit funny, so that might need adjusting but it's easier to do when the interface actually exists in the package - in the meantime this is a good example of this in action) |
c567474
to
c169183
Compare
d7659c8
to
acf03b4
Compare
Pushed a second iteration of the types. Still having problems with plugin-throttling.js/test/octokit.ts Line 37 in 054cefa
I get the following TS error:
Any clue on what could be the issue? @wolfy1339 @G-Rath
|
d9a4210
to
ab7bbab
Compare
ab7bbab
to
0011470
Compare
Blocked by octokit/core.js#451 resolution to update |
e92e997
to
750f3a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great PR, thanks for adding type checks!
🎉 This PR is included in version 3.6.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Description
To improve typing for
octokitOptions
forplugin-throttling
Context
It can be interesting for: